--! qt:dataset:src
set hive.multigroupby.singlereducer=true;

-- SORT_QUERY_RESULTS

CREATE TABLE DEST1_n47(key ARRAY<STRING>, value BIGINT) STORED AS TEXTFILE;
CREATE TABLE DEST2_n8(key MAP<STRING, STRING>, value BIGINT) STORED AS TEXTFILE;

EXPLAIN
FROM SRC
INSERT OVERWRITE TABLE DEST1_n47 SELECT ARRAY(SRC.key) as keyarray, COUNT(1) GROUP BY ARRAY(SRC.key) ORDER BY keyarray limit 10
INSERT OVERWRITE TABLE DEST2_n8 SELECT MAP(SRC.key, SRC.value) as kvmap, COUNT(1) GROUP BY MAP(SRC.key, SRC.value) ORDER BY kvmap limit 10;

FROM SRC
INSERT OVERWRITE TABLE DEST1_n47 SELECT ARRAY(SRC.key) as keyarray, COUNT(1) GROUP BY ARRAY(SRC.key) ORDER BY keyarray limit 10
INSERT OVERWRITE TABLE DEST2_n8 SELECT MAP(SRC.key, SRC.value) as kvmap, COUNT(1) GROUP BY MAP(SRC.key, SRC.value) ORDER BY kvmap limit 10;

SELECT DEST1_n47.* FROM DEST1_n47;
SELECT DEST2_n8.* FROM DEST2_n8;

